package com.outdoor.server.mapper;

import com.github.pagehelper.Page;
import com.outdoor.pojo.dto.EventPageQueryDTO;
import com.outdoor.pojo.entity.Event;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EventMapper {
    /**
     * 分页查询活动列表
     * @param eventPageQueryDTO
     * @return
     */
    Page<Event> pageQuery(EventPageQueryDTO eventPageQueryDTO);

    /**
     * 根据id查询活动详情
     * @param id
     * @return
     */
    @Select("SELECT * FROM event WHERE id = #{id}")
    Event getById(Long id);

    @Insert("INSERT INTO event(uid, title, description, cover, location, latitude, longitude, signup_start, " +
            "signup_end, start_time, end_time, status, created_by, phone, price, max_member) " +
            "VALUES" +
            "(#{uid}, #{title}, #{description}, #{cover}, #{location}, #{latitude}, #{longitude}, #{signupStart}, " +
            "#{signupEnd}, #{startTime}, #{endTime}, #{status}, #{createdBy}, #{phone}, #{price}, #{maxMember})      ")
    void insert(Event event);

    void update(Event event);

    /**
     * 根据id删除活动
     * @param id
     */
    @Delete("DELETE FROM event WHERE id = #{id}")
    void delete(Long id);


    /**
     * 查询所有活动列表
     * @return
     */
    @Select("SELECT * FROM event")
    List<Event> findAll();
}
